package thread01;

/**
 * 使用匿名内部类来完成两种方式的线程创建
 */
public class ThreadDemo3 {
    public static void main(String[] args) {
        //第一种：继承Thread重写run方法
        Thread t1 = new Thread() {
            public void run() {
                for (int i = 0; i < 1000; i++) {
                    System.out.println("你好帅！");
                }
            }
        };
        t1.start();

        //第二种：单独定义线程任务
     /* Runnable r2 = new Runnable() {
            public void run() {
                for(int i=0;i<1000;i++){
                    System.out.println("你真棒！");
                }
            }
        };
        Thread t2 = new Thread(r2); */

        /*Runnable接口可以使用lambda表达式创建
        Runnable r2 = ()->{
            for(int i=0;i<1000;i++){
                System.out.println("你真棒！");
            }
        };
        Thread t2 = new Thread(r2); */

        //再次简化
        Thread t2 = new Thread(() -> {
            for (int i = 0; i < 1000; i++) {
                System.out.println("你真棒！");
            }
        });
        t2.start();
    }
}
